﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace vkUpploaderLib.Objects
{
    public class Photo
    {
        public string Src { get; set; }
        public string SrcBig { get; set; }
        public string SrcxBig { get; set; }
        public string SrcxxBig { get; set; }
        public string SrcxxxBig { get; set; }
        public string SrcThumb { get; set; }
        public string Id { get; set; }

        public string AlbumId { get; set; }

        public string BiggestSrc
        {
            get
            {
                if (SrcxxxBig != null)
                {
                    return SrcxxxBig;
                }

                if (SrcxxBig != null)
                {
                    return SrcxxBig;
                }
                if (SrcxBig != null)
                {
                    return SrcxBig;
                }
                if (SrcBig != null)
                {
                    return SrcBig;
                }
                if (Src != null)
                {
                    return Src;
                }
                return null;
            }
        }

        public Photo(XElement photoXmlNode)
        {
            this.Id = photoXmlNode.Element("pid").Value;

            this.AlbumId = photoXmlNode.Element("aid").Value;

            if (photoXmlNode.Element("src") != null)
            {
                this.Src = photoXmlNode.Element("src").Value;
            }

            if (photoXmlNode.Element("src_xbig") != null)
            {
                this.SrcxBig = photoXmlNode.Element("src_xbig").Value;
            }

            if (photoXmlNode.Element("src_xxbig") != null)
            {
                this.SrcxxBig = photoXmlNode.Element("src_xxbig").Value;
            }

            if (photoXmlNode.Element("src_xxxbig") != null)
            {
                this.SrcxxBig = photoXmlNode.Element("src_xxxbig").Value;
            }

            if (photoXmlNode.Element("src_big") != null)
            {
                this.SrcBig = photoXmlNode.Element("src_big").Value;
            }

            this.SrcThumb = photoXmlNode.Element("src_small").Value;
        }
    }
}
